public class ToDoEntry extends AtomBase {

	public AtomDateTime duedate;
	public String activity;
	public String icon;
	public String position;
	public String assignedto;
	public String permissions; 
	public Element inreplyto;
	 
    public ToDoEntry() { }
	public ToDoEntry(AtomBase entry) {
		convertToToDo(entry);
	} 
	
	public void convertToToDo(AtomBase entry) {
		entry.clone(this);
		setDueDate(entry); 
		setActivity(entry);
		setPosition(entry);
		setAssignedto(entry);
		setPermissions(entry);
		setInReplyTo(entry);
		setDueDate(entry);
		setIcon(entry);
	}
	private void setIcon(AtomBase entry) {
		if (entry.extensions.containsKey('icon')) { 
			icon = entry.extensions.get('icon').value;
		}
	}
	private void setDueDate(AtomBase entry) {
		if (entry.extensions.containsKey('duedate')) { 
			duedate = new AtomDateTime(entry.extensions.get('duedate').value);
		}
	}
	private void setActivity(AtomBase entry) {
		if (entry.extensions.containsKey('activity')) { 
			activity = entry.extensions.get('activity').value;
		}
	}
	private void setPosition(AtomBase entry) {
		if (entry.extensions.containsKey('position')) { 
			position = entry.extensions.get('position').value;
		}
	}
	private void setAssignedto(AtomBase entry) {
		if (entry.extensions.containsKey('assignedto')) { 
			assignedto = entry.extensions.get('assignedto').value;
		}
	}
	private void setPermissions(AtomBase entry) {
		if (entry.extensions.containsKey('permissions')) { 
			permissions = entry.extensions.get('permissions').value;
		}
	}
	private void setInReplyTo(AtomBase entry) {
		if (entry.extensions.containsKey('inreplyto')) { 
			inreplyto = entry.extensions.get('inreplyto');
		} 
	} 
			
	public ToDoEntry(XmlStreamReader reader) {
		super(reader);
		addNamespace('', '');
	}
    public override String ExtensionsToAPP() {
    	String out = '';
    	out += getDueDateElement();
    	out += getIconElement();
    	out += getPositionElement();
    	out += getAssignedToElement();
        return out;
    }

    public override void ParseExtensionStartTag(XmlStreamReader reader, String nodeName) {
    }
    /*public override void ParseExtensionEndTag(XmlStreamReader reader, String nodeText) {
    	String nodeName = reader.getLocalName();
		if (nodeName == 'duedate') {
			duedate = Datetime.valueOf(nodeText.replaceAll('T', ' '));
		} else if (nodename == 'icon') {
			icon = nodeText;
		} else if (nodeName == 'position') {
			position = nodeText;
		} else if (nodeName == 'assignedto') {
			assignedto = nodeText;
		}    	
    }*/
    public String getPositionElement() {
    	String out = '';
    	if (position != null) {
    		out = '<snx:position>' + position + '</snx:position>\n';
    	}
    	return out;
    }
    public String getAssignedToElement() {
    	String out = '';
    	if (assignedto != null) {
    		out = '<snx:assignedto>' + assignedto + '</snx:assignedto>\n';
    	}
    	return out;
    }
	public String getIconElement() {
		String out = '';
		if (icon != null) {
			out = '<snx:icon>' + icon + '</snx:icon>\n';
		}
		return out;
	}
	
	public String getDueDateElement() {
		String out = '';
		if (duedate != null) {
			out = '<snx:duedate>' + duedate.getAtomString() + '</snx:duedate>\n';
		}
		return out;
	}
}